//
//  THJStorePurchaseDetailVC.m
//  THJXHW
//
//  Created by 河南德艺 on 2017/11/7.
//  Copyright © 2017年 河南德艺. All rights reserved.
//

#import "THJStorePurchaseDetailVC.h"
#import "THJTAdePurchaseVC.h"
#import "ZBNetworking.h"
#import "UIButton+ImageTitleSpacing.h"
@interface THJStorePurchaseDetailVC ()
{
    NSDictionary * qiugouDetailDic;
}
@property (weak, nonatomic) IBOutlet UIButton *shareBtn;
@end

@implementation THJStorePurchaseDetailVC
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setStateBarColor:[UIColor clearColor]];
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController.navigationBar setHidden:YES];
    [self getData];
    [self.shareBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleTop imageTitleSpace:5];
    // Do any additional setup after loading the view from its nib.
}
-(void)getData{
    NSLog(@"求购平台");
    [MBProgressHUD showMessage:@"" toView:self.view];
    __weak typeof(self) weakself = self;
    [ZBRequestManager requestWithConfig:^(ZBURLRequest *request){
        request.urlString= [NSString stringWithFormat:@"%@index.php?f=buy_6&r=buy_6&m=info&itemid=%@",THJUrlDomain,self.itemid];
        NSLog(@"求购列表详情-url--%@",request.urlString);
        request.apiType=ZBRequestTypeCache;
    }  success:^(id responseObject,apiType type){
        NSDictionary * receiveData = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"qiugou-%@",receiveData);
        
        [MBProgressHUD hideHUDForView:weakself.view animated:YES];
        if([receiveData[@"status"] isEqual:@"200"]){
            qiugouDetailDic = receiveData[@"data"];
            dispatch_async(dispatch_get_main_queue(), ^{
                [self setUIWithDic:receiveData[@"data"]];
            });
        }
    } failed:^(NSError *error){
    }];
}
-(void)setUIWithDic:(NSDictionary*)dic{
    NSString * guige = [THJTools guigeTypeChangeToStrWithType:dic[@"gg"]];
    self.titleLab.text = dic[@"title"];
    self.lab1.text = [NSString stringWithFormat:@"分类:%@",dic[@"catname"]];
    self.lab2.text = [NSString stringWithFormat:@"采购数量:%@",dic[@"cainum"]];
    self.lab3.text = [NSString stringWithFormat:@"规格:%@",guige];
    NSString * price = dic[@"price"];
    if(price.length){
         self.lab4.text = [NSString stringWithFormat:@"价格:￥%@/吨",dic[@"price"]];
    }else{
        self.lab4.text = @"价格洽谈";
    }
    self.lab5.text = [NSString stringWithFormat:@"交货地:%@",dic[@"address"]];
    self.addressLab.text = dic[@"address"];
    self.companyLab.text = dic[@"company"];
    self.timeLab.text = [NSString stringWithFormat:@"发布时间:%@", [self timeChangeWithString:dic[@"addtime"]]];
    [self.companyLogImgV sd_setImageWithURL:[NSURL URLWithString:dic[@"clogo"]] placeholderImage:kGetImage(@"占位图")];
}
- (IBAction)goBackAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)shareBtnAction:(id)sender {
    
    NSString * shareUrl = [NSString stringWithFormat:@"http://bigdata.thjb.net/dist/#/phonewantbuydetail/%@",self.itemid];
    [self shareWithContent:[NSString stringWithFormat:@"%@%@%@",self.companyLab.text,self.titleLab.text,self.lab4.text] Title:self.titleLab.text Url:shareUrl];
}
//他的求购
- (IBAction)TAdeQiuGou:(id)sender {
    THJTAdePurchaseVC * vc = [THJTAdePurchaseVC new];
    vc.cid = qiugouDetailDic[@"userid"];
    [self.navigationController pushViewController:vc animated:YES];
}
- (IBAction)phoneBtnAction:(id)sender {
    NSString * str;
    if(qiugouDetailDic[@"tel"]){
      str  = [NSString stringWithFormat:@"telprompt://%@",qiugouDetailDic[@"tel"]];
    }else{
        str = @"telprompt://400-999-6014";
    }
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}
@end
